//package com.plian.system.service.tb.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.plian.Tools.CollectionUtil;
//import com.plian.Tools.StringUtil;
//import com.plian.system.constant.tb.TripleStatusConstant;
//import com.plian.system.entity.tb.*;
//import com.plian.system.mapper.tb.MeetingMinutesMapper;
//import com.plian.system.mapper.tb.TripleMeetingMapper;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.service.tb.*;
//import com.plian.system.vo.tb.MeetingMinutesVO;
//import com.plian.system.wrapper.tb.MeetingMinutesWrapper;
//import lombok.AllArgsConstructor;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//import java.util.Optional;
//import java.util.stream.Collectors;
//
///**
// * @Author: Take-off
// * @Description: TODO 会议纪要
// * @Date: 2022/12/29 2:04 PM
// * @Version: 1.0
// **/
//@Service
//@AllArgsConstructor
//public class MeetingMinutesServiceImpl extends BaseServiceImpl<MeetingMinutesMapper, MeetingMinutes> implements IMeetingMinutesService {
//
//    private FileService fileService;
//
//    private final ITopicRelevanceService topicRelevanceService;
//
//    private final ITripleMeetingTopicService meetingTopicService;
//
//    private final IMeetingParticipantService meetingParticipantService;
//
//    private final IMeetingAttendeeService meetingAttendeeService;
//
//    private final ITripleSystemService tripleSystemService;
//
//    private final ITripleEventService tripleEventService;
//
//    private final MeetingMinutesWrapper meetingMinutesWrapper;
//
//    private final TripleMeetingMapper meetingMapper;
//    @Override
//    public boolean saveOrUpdate(MeetingMinutes meetingMinutes) {
//        boolean flag = false;
//        if (!Optional.ofNullable(meetingMinutes.getId()).isPresent()) {
//            flag = true;
//        }
//        boolean result = super.saveOrUpdate(meetingMinutes);
//        if (flag){
//            fileService.saveAll(String.valueOf(meetingMinutes.getId()), meetingMinutes.getDocList());
//        }else {
//            fileService.edit(String.valueOf(meetingMinutes.getId()), meetingMinutes.getDocList());
//        }
//        if (StringUtil.isNotBlank(meetingMinutes.getSummaryAttachId())){
//            fileService.upYthFile(meetingMinutes.getSummaryAttachId(),String.valueOf(meetingMinutes.getId()));
//        }
//        return result;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 保存
//     * @Date: 3:11 PM 2022/12/29
//     * @Param: [meetingMinutes]
//     * @return: boolean
//     **/
//    @Override
//    public boolean submit(MeetingMinutes meetingMinutes){
//        boolean result = saveOrUpdate(meetingMinutes);
//        if (result){
//            //修改会议状态
//            Long meetId = meetingMinutes.getBaseMeetingId();
//            TripleMeeting tripleMeeting = meetingMapper.selectById(meetId);
//            tripleMeeting.setMeetStatus(TripleStatusConstant.FINISHRECORD);
//            meetingMapper.updateById(tripleMeeting);
//            //议题
//            List<TripleMeetingTopic> meetingTopics = meetingMinutes.getMeetingTopics();
//            if (CollectionUtil.isNotEmpty(meetingTopics)){
//                for (TripleMeetingTopic meetingTopic:meetingTopics){
//                    //关联信息
//                    List<TopicRelevance> topicRelevances = meetingTopic.getTopicRelevances();
//                    topicRelevances.forEach(topicRelevance -> {
//                        //修改事项/制度的状态
//                        if (topicRelevance.getRelevanceType() == 1){
//                            //事项
//                            TripleEvent tripleEvent = tripleEventService.getById(topicRelevance.getRelevanceId());
//                            tripleEvent.setEventStatus(topicRelevance.getResult());
//                            tripleEventService.saveOrUpdate(tripleEvent);
//                        }else {
//                            //制度
//                            TripleSystem tripleSystem = tripleSystemService.getById(topicRelevance.getRelevanceId());
//                            tripleSystem.setSystemStatus(topicRelevance.getResult());
//                            tripleSystemService.saveOrUpdate(tripleSystem);
//                        }
//                        topicRelevanceService.saveOrUpdate(topicRelevance);
//                    });
//                }
//            }
//            //参会人
//            List<MeetingParticipant> meetingParticipants = meetingMinutes.getMeetingParticipants();
//            if (CollectionUtil.isNotEmpty(meetingParticipants)){
//                meetingParticipants.forEach(m ->{
//                    meetingParticipantService.saveOrUpdate(m);
//                });
//
//            }
//            //列席人
//            List<MeetingAttendee> meetingAttendees = meetingMinutes.getMeetingAttendees();
//            if (CollectionUtil.isNotEmpty(meetingAttendees)){
//                meetingAttendees.forEach(m ->{
//                    meetingAttendeeService.saveOrUpdate(m);
//                });
//            }
//        }
//        return result;
//    }
//
//    /**
//     * @Author: Take-off
//     * @Description: //TODO 修饰详情
//     * @Date: 9:38 AM 2023/1/5
//     * @Param: [meetingMinutesVO]
//     * @return: void
//     **/
//    @Override
//    public MeetingMinutesVO getDetailObj(MeetingMinutes meetingMinutes){
//        MeetingMinutesVO meetingMinutesVO = new MeetingMinutesVO();
//        if (Optional.ofNullable(meetingMinutes.getId()).isPresent()){
//            MeetingMinutes one = getOne(Condition.getQueryWrapper(meetingMinutes));
//            meetingMinutesVO = meetingMinutesWrapper.entityToVO(one);
//        }
//        //会议Id
//        Long baseMeetingId = null;
//        if (Optional.ofNullable(meetingMinutes.getBaseMeetingId()).isPresent()){
//            baseMeetingId = meetingMinutes.getBaseMeetingId();
//        }else {
//            baseMeetingId = meetingMinutesVO.getBaseMeetingId();
//        }
//
//        //获取议题
//        List<TripleMeetingTopic> tripleMeetingTopics = meetingTopicService.list(new LambdaQueryWrapper<TripleMeetingTopic>().eq(TripleMeetingTopic::getBaseMeetingId, baseMeetingId).orderByAsc(TripleMeetingTopic::getSerialNumber));
//        //set 议题关联信息
//        if (CollectionUtil.isNotEmpty(tripleMeetingTopics)){
//            List<TopicRelevance> topicRelevances = topicRelevanceService.list(new LambdaQueryWrapper<TopicRelevance>().eq(TopicRelevance::getBaseMeetingId, baseMeetingId));
//            if (CollectionUtil.isNotEmpty(topicRelevances)){
//                tripleMeetingTopics.forEach(topic ->{
//                    List<TopicRelevance> relevances = topicRelevances.stream().filter(m -> m.getTopicId().equals(topic.getId())).collect(Collectors.toList());
//                    topic.setTopicRelevances(relevances);
//                });
//            }
//        }
//        meetingMinutesVO.setMeetingTopics(tripleMeetingTopics);
//        //参会人
//        List<MeetingParticipant> meetingParticipants = meetingParticipantService.list(new LambdaQueryWrapper<MeetingParticipant>().eq(MeetingParticipant::getBaseMeetingId, baseMeetingId).orderByAsc(MeetingParticipant::getSerialNumber));
//        meetingMinutesVO.setMeetingParticipants(meetingParticipants);
//        //列席人
//        List<MeetingAttendee> meetingAttendees = meetingAttendeeService.list(new LambdaQueryWrapper<MeetingAttendee>().eq(MeetingAttendee::getBaseMeetingId, baseMeetingId).orderByAsc(MeetingAttendee::getSerialNumber));
//        meetingMinutesVO.setMeetingAttendees(meetingAttendees);
//
//        return meetingMinutesVO;
//    }
//
//
//}
